<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui 的主题样式  和  easyui 提供的图标样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />
<!-- 引入jquery 和  easyui.js   中文设置js-->
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>新增角色页面</title>
</head>
<script type="text/javascript">
$(function() {
	//自定义validatebox验证
	$.extend($.fn.validatebox.defaults.rules, {  
	    //验证角色名  
	      rolename : {// 验证角色名，可以是中文或英文
            validator : function(value) {
                return /^[\Α-\￥]+$/i.test(value)|/^\w+[\w\s]+\w+$/i.test(value);
             },
            message : '角色名为中文或英文'
     },
	})
	
	$('#xzjs').window({    
		title:'新增角色',
		width:500,
		height:400,
		collapsible:false,
		closable:true,
		minimizable:false,
		maximizable:false
	});
	//配置角色框
	$('#rname').textbox({    
		iconCls:'icon-man', 
		iconAlign:'left' ,
		prompt:"请输入角色信息"    
	});
	//配置权限框
	$('#xzfuncs').combotree({
		url:"fun",
		multiple:true,
		onlyLeafCheck:true,
		panelHeight: 'auto',
		onLoadSuccess: function () { 
	        }, 
	        
	});
	
	//提交
	$('#sve').linkbutton({    
		onClick:function(){
			var ck =$('#xzfuncs').combotree('tree').tree('getChecked');
			var path = new Array();
			for (var i = 0; i < ck.length; i++) {
				var parent=ck[i];
		        var tree = $('#xzfuncs').combotree('tree'); 
		          do { 
		            path.unshift(parent.id); 
		            var parent = tree.tree('getParent', parent.target); 
		          } while (parent); 
			}
			path.sort();
			var newArr=[];//新建一个新数组
            //遍历参数数组array
            for(var i=0;i<path.length;i++){
                //判断新数组是否有这个元素值，没有的话，就把arr[i]给push到新数组newArr中
                if(newArr.indexOf(path[i])===-1){
                    newArr.push(path[i]);
                }
            }
			var rname =$('#rname').val();
			$.ajax({
		    url:'addRole', 
			type:'post',
		    data:{'rname':rname,'func':newArr},
		    traditional:true,
		    dataType:'text',
		    success:function(date){    
		       if(date=="1"){
		    	   $.messager.show({
		    			title:'信息提示',
		    			msg:'添加成功',
		    			timeout:3000,
		    			showType:'slide'
		    		});
		    	   $("#xzrole").form('clear'); 
		       }else{
		    	   $.messager.show({
		    			title:'信息提示',
		    			msg:'该角色已存在,添加失败',
		    			timeout:3000,
		    			showType:'slide'
		    		});
		       } 
		    }})
		    }    
		}); 

	$('#cancl1').linkbutton({
			onClick:function(){
				window.location.reload();  										
			}
		})
})
</script>
<body>
<div id="xzjs" class="easyui-dialog"  buttons="#dlg-buttons "  > 
	<div id="xzJ" style="margin-left: 100px; margin-top: 50px">
		<form id="xzrole" method="post">
				角色：<input id="rname" class="easyui-validatebox" name="rname" type="text" 
				style="width: 200px" required="true" validType="rolename">
				<br>
				权限选择：<input id="xzfuncs"  name="rids" style="width: 180px" >
				<br>
		</form>
	</div>     
       <div id="dlg1-buttons" style="margin-top:10px;text-align: center;" >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id="sve"  class="easyui-linkbutton"  iconcls="icon-save">确定</button>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id="cancl1" class="easyui-linkbutton" onclick="javascript:$('#updateOrders').dialog('close')" iconcls="icon-cancel">取消</a>
</div>      
      </div>
</body>
</html>